package com.cdz.charger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cdz.charger.vo.LocationsVo;
import com.cdz.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.charger.domain.Locations;
import com.cdz.charger.service.ILocationsService;
import com.cdz.common.utils.poi.ExcelUtil;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 位置Controller
 *
 * @author baefengk2
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/charger/locations" )
@Api(tags = "位置相关接口" )
public class LocationsController extends BaseController {
    @Autowired
    private ILocationsService locationsService;

    /**
     * 查询位置列表
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:list')" )
    @GetMapping("/list" )
    @ApiOperation(value = "获取位置列表" )
    public TableDataInfo<List<Locations>> list(Locations locations) {
        startPage();
        List<Locations> list = locationsService.selectLocationsList(locations);
        return getDataTable(list);
    }

    /**
     * 导出位置列表
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:export')" )
    @Log(title = "位置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    @ApiOperation("导出位置列表" )
    public void export(HttpServletResponse response, Locations locations) {
        List<Locations> list = locationsService.selectLocationsList(locations);
        ExcelUtil<Locations> util = new ExcelUtil<Locations>(Locations. class);
        util.exportExcel(response, list, "位置数据" );
    }

    /**
     * 获取位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:query')" )
    @GetMapping(value = "/{id}" )
    @ApiOperation("获取位置详细信息" )
    public R<Locations> getInfo(@ApiParam(value = "位置ID" , required = true)
                                   @PathVariable("id" ) Long id) {
                return R.ok(locationsService.selectLocationsById(id));
    }

    /**
     * 新增位置
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:add')" )
    @Log(title = "位置" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增位置" )
    public AjaxResult add(@ApiParam(value = "位置实体" , required = true) @RequestBody Locations locations) {
        return toAjax(locationsService.insertLocations(locations));
    }

    /**
     * 修改位置
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:edit')" )
    @Log(title = "位置" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改位置" )
    public AjaxResult edit(@ApiParam(value = "位置实体" , required = true) @RequestBody Locations locations) {
        return toAjax(locationsService.updateLocations(locations));
    }

    /**
     * 删除位置
     */
    @PreAuthorize("@ss.hasPermi('charger:locations:remove')" )
    @Log(title = "位置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @ApiOperation("删除位置" )
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组" ) @PathVariable Long[] ids) {
        return toAjax(locationsService.deleteLocationsByIds(ids));
    }

    /**
     * 获取所有位置信息
     * @return
     */
    @GetMapping("/all" )
    @ApiOperation("获取所有位置信息" )
    public R<List<LocationsVo>> getAllLocations() {
        List<LocationsVo> list = locationsService.getAllLocations();
        return R.ok(list);
    }
}
